package main

import (
	"fmt"
)

//Talk
type Talk interface {
	talk()
	end()
}
type Run interface {
	run()
}
type Man struct {
}

type Woman struct {
}

//会议
type Meeting struct {
}

func (man Man) talk() {
	fmt.Println("man say talk")
}
func (man Man) run() {
	fmt.Println("man Run")
}
func (man Man) manFun() {
	fmt.Println("i am man")
}
func testRunInterface(run Run) {
	run.run()
}
func (w Woman) talk() {
	fmt.Println("woman say talk")
}

func (man Man) end() {
	fmt.Println("man end")
}

func (w Woman) end() {
	fmt.Println("woman end")
}

func (m *Meeting) startMeeting(talk Talk) {
	talk.talk()
}
func (m *Meeting) endMeeting(talk Talk) {
	talk.end()
}

//自定义数据类型实现接口
type cusInt int

func (ci cusInt) talk() {
	fmt.Println("cus talk")
}
func (ci cusInt) end() {
	fmt.Println("cus end")
}
func main() {
	//multiTest := MultiTest{}
	//var a A = multiTest
	//a.aFun()
	//var b B = multiTest
	//b.bFun()
	//var c C = multiTest
	//c.aFun()
	//c.cFun()
	//fmt.Println("test....")
	//test(multiTest)
	//var empty interface{}=a
	//fmt.Println(empty)

	//meeting := Meeting{}
	//man := Man{}
	//woman := Woman{}
	//meeting.startMeeting(man)
	//meeting.startMeeting(woman)
	//meeting.endMeeting(man)
	//meeting.endMeeting(woman)

	////自定义数据类型实现接口
	//var myInt cusInt
	//meeting.startMeeting(myInt)
	//meeting.endMeeting(myInt)
	//

	////man 实现多个接口
	//var runI Run = man
	//runI.run()
	//testRunInterface(man)

	/*	var orderSlice OrderSlice
		rand.Seed(time.Now().UnixNano())
		for i := 0; i < 5; i++ {
			order := Order{
				Name:  "order:" + strconv.Itoa(i),
				price: rand.Intn(100) * (i),
			}
			orderSlice = append(orderSlice, order)
		}
		fmt.Println("sort 前:", orderSlice)
		sort.Sort(orderSlice)
		fmt.Println(orderSlice)*/
	assert()
}
func assert() {
	var talks []Talk
	talks = append(talks, &Man{})
	talks = append(talks, &Woman{})
	for i := 0; i < len(talks); i++ {
		fmt.Printf("%T\n", talks[i])
		if man, ok := talks[i].(*Man); ok {
			man.manFun()
		} else {
			talks[i].talk()
			talks[i].end()
		}
	}
}

type Order struct {
	Name  string
	price int
}
type OrderSlice []Order

func (os OrderSlice) Len() int {
	return len(os)
}
func (os OrderSlice) Less(i, j int) bool {
	return os[i].price < os[j].price
}

func (os OrderSlice) Swap(i, j int) {
	os[i], os[j] = os[j], os[i]
}

type A interface {
	aFun()
}
type B interface {
	bFun()
}
type C interface {
	cFun()
	bFun()
	A
	B
}
type MultiTest struct {
}

func (m MultiTest) aFun() {
	fmt.Println("multi aFUn")
}
func (m MultiTest) bFun() {
	fmt.Println("multi bFun")
}
func (m MultiTest) cFun() {
	fmt.Println("multi cFun")
}
func test(c C) {
	c.aFun()
	c.bFun()
	c.cFun()
}
